home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
WindowColorMap.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-26
|
3KB
|
157 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "WindowColorMap.h"
#include "Class.h"
#include "String.h"
//---- WindowColorMap -------------------------------------------------------
NewMetaImpl(WindowColorMap,Object, (T(id), TB(rw), T(changed)));
int WindowColorMap::cnt= 1000;
WindowColorMap::WindowColorMap()
{
id= WindowColorMap::cnt++;
changed= 0;
rw= TRUE;
grey= FALSE;
}
WindowColorMap::WindowColorMap(WindowColorMap *from)
{
id= WindowColorMap::cnt++;
changed= 0;
rw= from->rw;
grey= from->grey;
}
WindowColorMap::~WindowColorMap()
{
}
WindowColorMap *WindowColorMap::DevMakeCopy(WindowColorMap*)
{
return this;
}
void WindowColorMap::Unref()
{
if (refcnt > 0) {
refcnt--;
if (refcnt == 0)
delete this;
}
}
u_long WindowColorMap::AllocateAndSetCell(long id, RGB *rgb, WindowPort *port)
{
if (rw)
return DevAllocateAndSetCell(id, rgb, port);
return RGB2Index(rgb);
}
void WindowColorMap::DevInstall(Port*)
{
changed= 0;
}
u_long WindowColorMap::DevRGB2Index(RGB *c, RGB*)
{
return DevRGB2Index2(c);
}
u_long WindowColorMap::DevRGB2Index2(RGB*)
{
return 0;
}
void WindowColorMap::DevIndex2RGB(u_long, RGB*)
{
}
u_long WindowColorMap::DevAllocateAndSetCell(long, RGB*, WindowPort*)
{
return 0;
}
//---- WindowColorMap -------------------------------------------------------
NewMetaImpl(WindowIndexMapper,WindowColorMap, (T(length)));
WindowIndexMapper::WindowIndexMapper() : WindowColorMap()
{
length= 0;
realmap= new RGB[256];
graymap= new u_long[256];
rgbmap= new u_long[256];
}
WindowIndexMapper::WindowIndexMapper(WindowIndexMapper *from)
: WindowColorMap(from)
{
length= from->length;
realmap= new RGB[256];
memcpy(realmap, from->realmap, 256 * sizeof(RGB));
graymap= new u_long[256];
memcpy(graymap, from->graymap, 256 * sizeof(u_long));
rgbmap= new u_long[256];
memcpy(rgbmap, from->rgbmap, 256 * sizeof(u_long));
}
WindowIndexMapper::~WindowIndexMapper()
{
SafeDelete(realmap);
SafeDelete(graymap);
SafeDelete(rgbmap);
}
u_long WindowIndexMapper::DevRGB2Index(RGB *c, RGB *result)
{
u_long id, ix;
if (grey || (c->red == c->green && c->green == c->blue)) {
if (grey)
id= c->AsGreyLevel();
else
id= c->red;
ix= graymap[id];
if (ix == 0) {
RGB rc((short)((id / (MAXGREYS-1)) * (MAXGREYS-1)));
graymap[id]= ix= DevRGB2Index2(&rc);
}
/*
if (type[ix])
ix= graymap[v]= FindGray(v);
*/
} else {
id= Pixel(c->red, c->green, c->blue);
ix= rgbmap[id];
if (ix == 0) {
RGB rc;
rc.red= (c->red / (MAXREDS-1)) * (MAXREDS-1);
rc.green= (c->green / (MAXGREENS-1)) * (MAXGREENS-1);
rc.blue= (c->blue / (MAXBLUES-1)) * (MAXBLUES-1);
rgbmap[id]= ix= DevRGB2Index2(&rc);
}
/*
if (type[ix])
ix= FindRGB(c);
*/
}
// usecnt[ix]++;
if (result)
*result= realmap[ix];
return ix;
}
void WindowIndexMapper::DevIndex2RGB(u_long ix, RGB *result)
{
*result= realmap[ix];
}